package com.jsonal.controller.manager;

import com.jsonal.controller.BaseController;
import com.jsonal.entity.manager.MenuBean;
import com.jsonal.form.manager.MenuForm;
import com.jsonal.service.manager.MenuService;
import com.jsonal.vo.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author: jingji.lin
 * @Description:
 * @Date: 2020/6/16 8:55
 * @Version: 1.0
 */
@Controller
public class MenuController extends BaseController {

    @Autowired
    private MenuService menuService;

    @RequestMapping(value = "/managers/addOrUpdateMenu", method = RequestMethod.POST)
    @ApiOperation(value = "/managers/addOrUpdateMenu", httpMethod = "POST", notes = "添加或修改菜单")
    @ResponseBody
    public Result addOrUpdateMenu(@RequestBody MenuForm menuForm) {
        MenuBean menuBean = new MenuBean();
        this.setFormToBean3(menuForm, menuBean);
        return menuService.addOrUpdateMenu(menuBean);
    }

    @RequestMapping(value = "/managers/getMenuList", method = RequestMethod.GET)
    @ApiOperation(value = "/managers/getMenuList", httpMethod = "GET", notes = "获取菜单列表")
    @ResponseBody
    public Result getMenuList(MenuForm menuForm) {
        MenuBean menuBean = new MenuBean();
        this.setFormToBean3(menuForm, menuBean);
        return menuService.getMenuList(menuBean);
    }

    @RequestMapping(value = "/managers/getMenuById/{id}", method = RequestMethod.GET)
    @ApiOperation(value = "/managers/getMenuById/{id}", httpMethod = "GET", notes = "根据id获取菜单数据")
    @ResponseBody
    public Result getMenuById(@PathVariable String id) {
        if (id == null || "".equals(id)) {
            return new Result(false, "id为空");
        }
        return menuService.getMenuById(id);
    }

    @RequestMapping(value = "/managers/getMenus", method = RequestMethod.GET)
    @ApiOperation(value = "/managers/getMenus", httpMethod = "GET", notes = "获取全部菜单")
    @ResponseBody
    public Result getMenus() {
        return menuService.getMenus();
    }

    @RequestMapping(value = "/managers/removeMenu/{id}", method = RequestMethod.POST)
    @ApiOperation(value = "/managers/removeMenu/{id}", httpMethod = "POST", notes = "根据 id 删除菜单")
    @ResponseBody
    public Result removeMenu(@PathVariable String id) {
        if (id == null || "".equals(id)) {
            return new Result(false, "id为空");
        }
        return menuService.removeMenu(id);
    }
}
